"""
Copyright (c) 2022 Huawei Technologies Co.,Ltd.

openGauss is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:

          http://license.coscl.org.cn/MulanPSL2

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
"""
"""
Case Type   : SQL_DDL_Drop_Owned
Case Name   : 使用元命令\h 查询语法
Create At   : 2022/08/25
Owner       : @li-xin12345
Description :
    1.\h DROP OWNED 命令查询语法描述是否准确
    2.\h REASSIGN OWNED 命令查询语法描述是否准确
Expect      :
    1.DROP OWNED语法描述准确
    2.REASSIGN OWNED语法描述准确
History     :
"""
import os
import unittest
from testcase.utils.Logger import Logger
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from yat.test import Node
from yat.test import macro


class DropOwned(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f"-----{os.path.basename(__file__)} start-----")
        self.user_node = Node('PrimaryDbUser')
        self.primary_sh = CommonSH('PrimaryDbUser')
        self.constant = Constant()

    def test_drop_owned(self):
        text = r"-----step1:\h DROP OWNED 命令查询语法描述是否准确;" \
               r"expect:DROP OWNED语法描述准确-----"
        self.logger.info(text)
        sql_msg = self.primary_sh.execut_db_sql('\\h DROP OWNED')
        self.logger.info(sql_msg)
        self.assertIn('DROP OWNED BY name [, ...] [ CASCADE | RESTRICT ];',
                      sql_msg, '执行失败' + text)

        text = r"-----step2:\h REASSIGN OWNED 命令查询语法描述是否准确;" \
               r"expect:REASSIGN OWNED语法描述准确-----"
        self.logger.info(text)
        sql_msg = self.primary_sh.execut_db_sql('\\h REASSIGN OWNED')
        self.logger.info(sql_msg)
        self.assertIn('REASSIGN OWNED BY old_role [, ...] TO new_role;',
                      sql_msg, '执行失败' + text)

    def tearDown(self):
        self.logger.info("-----无需清理环境-----")
        self.logger.info(f"-----{os.path.basename(__file__)} end-----")
